const LOCAL_CONFIG_KEY = 'dtools-local-config'

const localConfig = {
  getConfig(): Promise<any> {
    const data: any = window.dtools.db.get(LOCAL_CONFIG_KEY) || {}
    return data.data
  },

  setConfig(data) {
    const localConfig: any = window.dtools.db.get(LOCAL_CONFIG_KEY) || {}
    window.dtools.db.put({
      _id: LOCAL_CONFIG_KEY,
      _rev: localConfig._rev,
      data: {
        ...localConfig.data,
        ...data
      }
    })
  }
}

export default localConfig
